package com.siwei.mes.entity.experiment.fineAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 细骨料-泥块含量
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FineAggregateNkhl {
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "泥块含量信息")
    private List<FineAggregateNkhl.HnkInfo> hnkInfo = Collections.singletonList(new FineAggregateNkhl.HnkInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("泥块含量信息")
    public static class HnkInfo {
        @ApiModelProperty(value = "烘前试样质量")
        private String hqsyzl = "";
        @ApiModelProperty(value = "烘后试样质量")
        private String hhsyzl = "";
        @ApiModelProperty(value = "泥块含量")
        private String hnl = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FineAggregateNkhl entity = new FineAggregateNkhl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FineAggregateNkhl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FineAggregateNkhl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FineAggregateNkhl entity = JsonUtils.getObject(objJson, FineAggregateNkhl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(FineAggregateNkhl entity, Map<String, Object> data) {
        List<FineAggregateNkhl.HnkInfo> hnkInfoList = new ArrayList<>();
        HnkInfo hnkInfoOne = new HnkInfo();
        if(data.get("S1") != null){
            hnkInfoOne.setHqsyzl(data.get("S1").toString());
        }
        if(data.get("S2") != null){
            hnkInfoOne.setHhsyzl(data.get("S2").toString());
        }
        if(data.get("S3") != null){
            hnkInfoOne.setHnl(data.get("S3").toString());
        }
        hnkInfoList.add(hnkInfoOne);
        HnkInfo hnkInfoTwo = new HnkInfo();
        if(data.get("S4") != null){
            hnkInfoTwo.setHqsyzl(data.get("S4").toString());
        }
        if(data.get("S5") != null){
            hnkInfoTwo.setHhsyzl(data.get("S5").toString());
        }
        if(data.get("S6") != null){
            hnkInfoTwo.setHnl(data.get("S6").toString());
        }
        hnkInfoList.add(hnkInfoTwo);
        entity.setHnkInfo(hnkInfoList);
        if(data.get("S7") != null){
            entity.setPjz(data.get("S7").toString());
        }
    }
}
